package com.lookup.api;

import java.util.function.Consumer;

import com.lookup.api.logger.LoggerWrapper;
import com.lookup.api.verticle.EventBusWorkerVerticle;
import com.lookup.api.verticle.HttpWorkerVerticle;

import io.vertx.core.DeploymentOptions;
import io.vertx.core.Promise;
import io.vertx.rxjava.core.AbstractVerticle;
import io.vertx.rxjava.core.Vertx;

public class RxApiServer extends AbstractVerticle {

	private static LoggerWrapper logger = new LoggerWrapper("init.server" + RxApiServer.class.getName());
	private static final int CPUS = Runtime.getRuntime().availableProcessors();

	@Override
	public void start(Promise<Void> startFuture) throws Exception {
		super.start(startFuture);
	}
//    @Override
//    public void start(Future<Void> startFuture) throws Exception {
//        super.start(startFuture);
//    }

	@Override
	public void start() throws Exception {

		Consumer<Vertx> runner = vertx -> {
			DeploymentOptions options = new DeploymentOptions();
			options.setInstances(CPUS);
			vertx.deployVerticle(HttpWorkerVerticle.class.getName(), options);
			vertx.deployVerticle(EventBusWorkerVerticle.class.getName(), options);
		};
		Vertx vertx = Vertx.vertx();
		runner.accept(vertx);

	}

	public static void main(String... args) {
		try {
			new RxApiServer().start();
		} catch (Exception e) {
			logger.error("  bootstrap error  ", e);
		}

	}

}
